Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[draft] flow callbacks for ndpi - v1 #11935

Closed
wants to merge 2 commits into from

Conversation

jasonish
Copy link
Member

In order for nDPI to become a plugin it needs to hook into flow initialization and flow updates. This PR provides user registerable flow callbacks for these events.

It also includes a "dummy" ndpi plugin using these callbacks, and also shows how to use the flow storage API to avoid modifying the Flow structure directly.

Original nDPI PR: #11671

Tickets:

Adds user registerable callbacks for flow initialization and flow
update.

Some plugins, such as other DPI libraries like nDPI need a way to hook
into these flow lifecycle events.

Ticket: OISF#7319
Ticket: OISF#7320
This plugin stub shows how a plugin like nDPI might be use the flow
init and flow update callbacks to do its work. Also shows usage of
FlowStorage to avoid modifying the Flow struct directly.
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 17.64706% with 28 lines in your changes missing coverage. Please review.

Project coverage is 82.73%. Comparing base (58556b7) to head (fe62c1c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11935      +/-   ##
==========================================
- Coverage   82.74%   82.73%   -0.01%     
==========================================
  Files         912      913       +1     
  Lines      249102   249136      +34     
==========================================
+ Hits       206117   206130      +13     
- Misses      42985    43006      +21     
Flag Coverage Δ
fuzzcorpus 60.71% <17.64%> (-0.01%) ⬇️
livemode 18.72% <17.64%> (-0.14%) ⬇️
pcap 44.11% <17.64%> (+<0.01%) ⬆️
suricata-verify 62.17% <17.64%> (-0.01%) ⬇️
unittests 58.98% <8.82%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

SCFree(ptr);
}

static void OnFlowInit(Flow *f, const Packet *p)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'd expect a OnFlowDestruct too, although perhaps we don't need it directly here, as the FlowStorage API knowns how to destroy the user data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, for completeness should probably add it. Not needed for storage cleanup using the storage API, and someone else uses the flow event for their private cleanup, but it does feel missing.

FlowSetStorageById(f, flow_storage_id, dummy_storage);
}

static void OnFlowUpdate(Flow *f, Packet *p, ThreadVars *tv)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should there be user data here as well? general user data? Perhaps not needed for ndpi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess more for the library, but if someone wanted to create a simple flow logger, they'd want to pass a file pointer around these callbacks to log a new flow creation, or a flow destruction, etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should have user data, was being short sighted and only looking at the case at hand which doesn't need it.

@jasonish
Copy link
Member Author

Replaced by #11942, all callbacks accept user data now.

@jasonish jasonish closed this Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants